<?php

namespace App\Http\Controllers\Admin\Pages;

use App\Facades\UserService;
use App\Facades\WxUserService;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Sentinel;

class UserController extends Controller
{   
    //管理员列表
    public function index()
    {
        $user = Sentinel::getUser();
        $adminInfoList = UserService::getAllAdminWithInfo($user);
        return view('admin/index')->with([
            'admin_infos' => $adminInfoList,
            ]);
    }
    //后台登录
    public function login(Request $request)
    {
        return view('admin/login');
    }

    //用户列表
    public function customerList(Request $request)
    {
        $condition = $request->condition;
        $condition = str_replace('%', '\%', $condition);
        $condition = str_replace('_', '\_', $condition);
    	$customerList = UserService::findCustomerListWithUserInfo($condition);
        return view('admin/customers')->with([
            'customer_list' => $customerList,
            'condition' => $request->condition,
            ]);
    }

    //售后服务列表
    public function afterServiceList(Request $request)
    {
        $afterServices = UserService::findAfterServiceList($request->condition);
        return view('admin/afterServices')->with([
            'after_services' => $afterServices,
            'condition' => $request->condition,
            ]);
    }

    public function chargeRecordsByUserId(Request $request)
    {
        $rules = [
            'user_id' => 'required|exists:users,id'
        ];
        $this->validate($request, $rules);
        
        $chargeRecords = ChargeRecordService::getChargeListByDeviceId(null, $request->user_id);
    }
}
